import type { HardhatUserConfig } from 'hardhat/config'

import hardhatKeystore from '@nomicfoundation/hardhat-keystore'
import hardhatToolboxMochaEthersPlugin from '@nomicfoundation/hardhat-toolbox-mocha-ethers'
import hardhatIgnitionEthersPlugin from '@nomicfoundation/hardhat-ignition-ethers'
import hardhatVerify from '@nomicfoundation/hardhat-verify'
import hardhatAccounts from '@solidstate/hardhat-accounts'

import { configVariable } from 'hardhat/config'
import { config as dotenv } from 'dotenv'
dotenv()

const config: HardhatUserConfig = {
  plugins: [
    // 插件:密文存储
    hardhatKeystore,
    // 插件:单元测试中支持ethers.js
    hardhatToolboxMochaEthersPlugin,
    // 插件:Ignition支持Ethers.js
    hardhatIgnitionEthersPlugin,
    // 插件:合约验证
    hardhatVerify,
    // 插件:查看账户信息
    hardhatAccounts
  ],
  solidity: {
    profiles: {
      default: {
        version: '0.8.28'
      },
      production: {
        version: '0.8.28',
        settings: {
          optimizer: {
            enabled: true,
            runs: 200
          }
        }
      }
    },
    npmFilesToBuild: [
      '@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol',
      '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol'
    ]
  },
  networks: {
    hardhatMainnet: {
      type: 'edr-simulated',
      chainType: 'l1'
    },
    hardhatOp: {
      type: 'edr-simulated',
      chainType: 'op'
    },
    sepolia: {
      timeout: 9999 * 1000,
      type: 'http',
      chainType: 'l1',
      url: configVariable('SEPOLIA_RPC_URL'),
      accounts: [configVariable('SEPOLIA_PRIVATE_KEY')]
    },
    mainnet: {
      timeout: 9999 * 1000,
      type: 'http',
      chainType: 'l1',
      url: configVariable('MAINNET_RPC_URL'),
      accounts: [configVariable('MAINNET_PRIVATE_KEY')]
    }
  },
  verify: {
    etherscan: {
      enabled: true,
      apiKey: configVariable('ETHERSCAN_API_KEY')
    },
    blockscout: {
      enabled: false
    }
  }
}

export default config
